<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="page_nav">
    <c:if test="${requestScope.page.pageNo != 1}">
        <a href="${requestScope.page.path}&pageNo=1">首页</a>
        <a href="${requestScope.page.path}&pageNo=${requestScope.page.pageNo-1}">上一页</a>
    </c:if>
    <c:choose>
        <c:when test="${requestScope.page.totalPage < 5}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="${requestScope.page.totalPage}"></c:set>
        </c:when>
        <c:when test="${requestScope.page.pageNo <= 2}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="5"></c:set>
        </c:when>
        <c:otherwise>
            <c:set var="begin" value="${requestScope.page.pageNo-2}"></c:set>
            <c:set var="end" value="${requestScope.page.pageNo+2}"></c:set>
            <c:if test="${pageScope.end > requestScope.page.totalPage}">
                <c:set var="begin" value="${requestScope.page.totalPage-4}"></c:set>
                <c:set var="end" value="${requestScope.page.totalPage}"></c:set>
            </c:if>
        </c:otherwise>
    </c:choose>
    <c:forEach begin="${pageScope.begin}" end="${pageScope.end}" var="i">
        <c:if test="${requestScope.page.pageNo == pageScope.i}">
            <a href="${requestScope.page.path}&pageNo=${pageScope.i}" style="color: red;">[${pageScope.i}]</a>
        </c:if>
        <c:if test="${requestScope.page.pageNo != pageScope.i}">
            <a href="${requestScope.page.path}&pageNo=${pageScope.i}">${pageScope.i}</a>
        </c:if>
    </c:forEach>
    <c:if test="${requestScope.page.pageNo != requestScope.page.totalPage}">
        <a href="${requestScope.page.path}&pageNo=${requestScope.page.pageNo+1}">下一页</a>
        <a href="${requestScope.page.path}&pageNo=${requestScope.page.totalPage}">末页</a>
    </c:if>
    共${requestScope.page.totalPage}页，${requestScope.page.totalCount}条记录 到第<input value="${requestScope.page.pageNo}" id="pn_input"/>页
    <input type="button" value="确定" id="btnId">
</div>
<script type="text/javascript">
    $(function () {
        $("#btnId").click(function () {
            //获取用户输入的页码
            var pageNo = $("#pn_input").val();
            location = "${requestScope.page.path}&pageNo="+pageNo;
        });
    });
</script>